/**
 * 作者: wgx
 * 日期: 2025-05-06 10:48:26
 * 备注: 用户展示数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserShow;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserShowModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_NOT;// 数据入库类型 不入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户ID
    protected String userName = ""; // 用户名称
    protected int level; // 等级
    protected String icon = ""; // 头像
    protected int iconFrame; // 头像框(不会到期)
    protected int serverId; // 服务器ID
    protected int vip; // vip等级
    protected String cityName = ""; // 城市名称
    protected int partnerNum; // 干员数量
    protected long power; // 总战力
    protected long earn; // 总城市收益
    protected int titleId; // 佩戴的称号
    protected int bubbleId; // 聊天气泡的id
    protected long unionId; // 联盟id
    protected String unionName = ""; // 联盟名称

    public void reset() {
    }

    protected String getKey() {
        return "UserShow." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_show"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入库
     */
    public JsonObject updateNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE_NOW, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户ID
        obj.put("userName", userName); // 用户名称
        obj.put("level", level); // 等级
        obj.put("icon", icon); // 头像
        obj.put("iconFrame", iconFrame); // 头像框(不会到期)
        obj.put("serverId", serverId); // 服务器ID
        obj.put("vip", vip); // vip等级
        obj.put("cityName", cityName); // 城市名称
        obj.put("partnerNum", partnerNum); // 干员数量
        obj.put("power", power); // 总战力
        obj.put("earn", earn); // 总城市收益
        obj.put("titleId", titleId); // 佩戴的称号
        obj.put("bubbleId", bubbleId); // 聊天气泡的id
        obj.put("unionId", unionId); // 联盟id
        obj.put("unionName", unionName); // 联盟名称
        return obj;
    }

    public PBUserShow.Builder takeInitBuilder() {
        PBUserShow.Builder sb = PBUserShow.newBuilder();
        if (id != 0) {
            sb.setId(id);
        }
        if (!userName.isEmpty()) {
            sb.setUserName(userName);
        }
        if (level != 0) {
            sb.setLevel(level);
        }
        if (!icon.isEmpty()) {
            sb.setIcon(icon);
        }
        if (iconFrame != 0) {
            sb.setIconFrame(iconFrame);
        }
        if (serverId != 0) {
            sb.setServerId(serverId);
        }
        if (vip != 0) {
            sb.setVip(vip);
        }
        if (!cityName.isEmpty()) {
            sb.setCityName(cityName);
        }
        if (partnerNum != 0) {
            sb.setPartnerNum(partnerNum);
        }
        if (power != 0) {
            sb.setPower(power);
        }
        if (earn != 0) {
            sb.setEarn(earn);
        }
        if (titleId != 0) {
            sb.setTitleId(titleId);
        }
        if (bubbleId != 0) {
            sb.setBubbleId(bubbleId);
        }
        if (unionId != 0) {
            sb.setUnionId(unionId);
        }
        if (!unionName.isEmpty()) {
            sb.setUnionName(unionName);
        }
        return sb;
    }

    public PBUserShow.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserShow.Builder sb = PBUserShow.newBuilder();
        if (isFieldUpdate("id")) {
            sb.setId(id);
        }
        if (isFieldUpdate("userName")) {
            sb.setUserName(userName);
        }
        if (isFieldUpdate("level")) {
            sb.setLevel(level);
        }
        if (isFieldUpdate("icon")) {
            sb.setIcon(icon);
        }
        if (isFieldUpdate("iconFrame")) {
            sb.setIconFrame(iconFrame);
        }
        if (isFieldUpdate("serverId")) {
            sb.setServerId(serverId);
        }
        if (isFieldUpdate("vip")) {
            sb.setVip(vip);
        }
        if (isFieldUpdate("cityName")) {
            sb.setCityName(cityName);
        }
        if (isFieldUpdate("partnerNum")) {
            sb.setPartnerNum(partnerNum);
        }
        if (isFieldUpdate("power")) {
            sb.setPower(power);
        }
        if (isFieldUpdate("earn")) {
            sb.setEarn(earn);
        }
        if (isFieldUpdate("titleId")) {
            sb.setTitleId(titleId);
        }
        if (isFieldUpdate("bubbleId")) {
            sb.setBubbleId(bubbleId);
        }
        if (isFieldUpdate("unionId")) {
            sb.setUnionId(unionId);
        }
        if (isFieldUpdate("unionName")) {
            sb.setUnionName(unionName);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public String getUserName() {
        return userName;
    }

    public void putUserName(String userName) {
        if (!this.userName.equals(userName)) {
            this.userName = userName;
            updateRedisHashField(getKey(), "userName", this.userName);
        }
    }

    public int getLevel() {
        return level;
    }

    public void putLevel(int level) {
        if (this.level != level) {
            this.level = level;
            updateRedisHashField(getKey(), "level", this.level);
        }
    }

    public void addLevel(int value) {
        this.level += value;
        updateRedisHashField(getKey(), "level", this.level);
    }

    public String getIcon() {
        return icon;
    }

    public void putIcon(String icon) {
        if (!this.icon.equals(icon)) {
            this.icon = icon;
            updateRedisHashField(getKey(), "icon", this.icon);
        }
    }

    public int getIconFrame() {
        return iconFrame;
    }

    public void putIconFrame(int iconFrame) {
        if (this.iconFrame != iconFrame) {
            this.iconFrame = iconFrame;
            updateRedisHashField(getKey(), "iconFrame", this.iconFrame);
        }
    }

    public void addIconFrame(int value) {
        this.iconFrame += value;
        updateRedisHashField(getKey(), "iconFrame", this.iconFrame);
    }

    public int getServerId() {
        return serverId;
    }

    public void putServerId(int serverId) {
        if (this.serverId != serverId) {
            this.serverId = serverId;
            updateRedisHashField(getKey(), "serverId", this.serverId);
        }
    }

    public void addServerId(int value) {
        this.serverId += value;
        updateRedisHashField(getKey(), "serverId", this.serverId);
    }

    public int getVip() {
        return vip;
    }

    public void putVip(int vip) {
        if (this.vip != vip) {
            this.vip = vip;
            updateRedisHashField(getKey(), "vip", this.vip);
        }
    }

    public void addVip(int value) {
        this.vip += value;
        updateRedisHashField(getKey(), "vip", this.vip);
    }

    public String getCityName() {
        return cityName;
    }

    public void putCityName(String cityName) {
        if (!this.cityName.equals(cityName)) {
            this.cityName = cityName;
            updateRedisHashField(getKey(), "cityName", this.cityName);
        }
    }

    public int getPartnerNum() {
        return partnerNum;
    }

    public void putPartnerNum(int partnerNum) {
        if (this.partnerNum != partnerNum) {
            this.partnerNum = partnerNum;
            updateRedisHashField(getKey(), "partnerNum", this.partnerNum);
        }
    }

    public void addPartnerNum(int value) {
        this.partnerNum += value;
        updateRedisHashField(getKey(), "partnerNum", this.partnerNum);
    }

    public long getPower() {
        return power;
    }

    public void putPower(long power) {
        if (this.power != power) {
            this.power = power;
            updateRedisHashField(getKey(), "power", this.power);
        }
    }

    public void addPower(long value) {
        this.power += value;
        updateRedisHashField(getKey(), "power", this.power);
    }

    public long getEarn() {
        return earn;
    }

    public void putEarn(long earn) {
        if (this.earn != earn) {
            this.earn = earn;
            updateRedisHashField(getKey(), "earn", this.earn);
        }
    }

    public void addEarn(long value) {
        this.earn += value;
        updateRedisHashField(getKey(), "earn", this.earn);
    }

    public int getTitleId() {
        return titleId;
    }

    public void putTitleId(int titleId) {
        if (this.titleId != titleId) {
            this.titleId = titleId;
            updateRedisHashField(getKey(), "titleId", this.titleId);
        }
    }

    public void addTitleId(int value) {
        this.titleId += value;
        updateRedisHashField(getKey(), "titleId", this.titleId);
    }

    public int getBubbleId() {
        return bubbleId;
    }

    public void putBubbleId(int bubbleId) {
        if (this.bubbleId != bubbleId) {
            this.bubbleId = bubbleId;
            updateRedisHashField(getKey(), "bubbleId", this.bubbleId);
        }
    }

    public void addBubbleId(int value) {
        this.bubbleId += value;
        updateRedisHashField(getKey(), "bubbleId", this.bubbleId);
    }

    public long getUnionId() {
        return unionId;
    }

    public void putUnionId(long unionId) {
        if (this.unionId != unionId) {
            this.unionId = unionId;
            updateRedisHashField(getKey(), "unionId", this.unionId);
        }
    }

    public void addUnionId(long value) {
        this.unionId += value;
        updateRedisHashField(getKey(), "unionId", this.unionId);
    }

    public String getUnionName() {
        return unionName;
    }

    public void putUnionName(String unionName) {
        if (!this.unionName.equals(unionName)) {
            this.unionName = unionName;
            updateRedisHashField(getKey(), "unionName", this.unionName);
        }
    }

}